--# -path=.:prelude:alltenses 
concrete SyllogismIta of Syllogism = LexiconSyllIta ** open SyntaxIta, (R=ResIta),(C=CatIta), (CR=CommonRomance), (P=ParadigmsIta), (Coord = Coordination), ParamX,Prelude in{ 
 

     lincat 
           Syllogism = {s : Str }; 
           Sentence  = {s : Str} ; 
           Subject   = {noun : C.CN; rel : C.RS; sort : Sort};
           Property  = R.VP;
           PropertyPart = { noun : C.CN; verb : R.VP; adj : C.A; 
                                    rel : C.RS; sort : Sort}; 
           Word = { noun : C.CN; verb : R.VP; adj : C.A;
                         rel : C.RS; sort : Sort};
                         
         Sentences = {s : Str};    
         Constant  = C.PN; 
         Const     = C.PN;
         AllQ      = {};
         NoQ       = {};

param Sort = SNoun | SAdj | SVerb ;

     lin
        AWord a = {noun = adjToCN a; verb = mkVP a; rel = mkRS (mkRCl which_RP (mkVP a)); adj = a; sort = SAdj};
        NWord n = {noun = mkCN n; verb = nounToVP n; rel = mkRS (mkRCl which_RP (nounToVP n)); adj = dummyAdj; sort = SNoun};
        VWord v = {noun = verbToCN  v; verb = mkVP v; rel = mkRS (mkRCl which_RP (mkVP v)); adj = dummyAdj; sort = SVerb};
        CWord c = c;


            
     CpP const prop = let ss = mkCl (mkNP const) prop
                                    in {s = ss.s  ! CR.DDir ! CR.RPres ! Simul ! Pos ! CR.Indic};
     CnP const prop = let ss = mkCl (mkNP const) prop
                                    in {s = ss.s ! CR.DDir ! CR.RPres ! Simul ! Neg ! CR.Indic};

     SaP _ sub prop =  let det = all_Det | every_Det ;
                                       ss = case sub.sort of 
                                                  {  SNoun => mkCl (mkNP det sub.noun) prop;
                                                     _          => mkCl (mkNP (mkNP det) sub.rel) prop}
                                    in {s = ss.s ! CR.DDir ! CR.RPres ! Simul ! Pos ! CR.Indic}; 

     SoP sub prop = let det = some_Det ;
                                   ss = case sub.sort of 
                                                  { SNoun => mkCl (mkNP det sub.noun) prop;
                                                     _         => mkCl (mkNP (mkNP det) sub.rel) prop}
                                    in {s = ss.s ! CR.DDir ! CR.RPres ! Simul ! Neg ! CR.Indic};      
     SeP _ sub prop = let det = no_Det ; 
                                     ss = case sub.sort of 
                                                  { SNoun => mkCl (mkNP det sub.noun) prop;
                                                     _         => mkCl (mkNP (mkNP det) sub.rel) prop} 
                                     in {s = ss.s ! CR.DDir ! CR.RPres ! Simul ! Neg ! CR.Indic};
     SiP sub prop = let det = some_Det ;
                                   ss = case sub.sort of 
                                                  { SNoun => mkCl (mkNP det sub.noun) prop;
                                                     _         => mkCl (mkNP (mkNP det) sub.rel) prop}
                                    in {s = ss.s ! CR.DDir ! CR.RPres ! Simul ! Pos ! CR.Indic};
      
     ToProperty ppart = ppart.verb ;  
     ToSubject  sWord  = {noun = sWord.noun; rel = sWord.rel; sort = sWord.sort}; 
     ToConstant const = const;
     ToPropertyPart word = word; 


     ToConclusion sent = sent; 
     
     mkSyllogism ss c = {s = "(" ++ ss.s ++ ") ->" ++ c.s};
     mkSentences s1 s2  = {s = s1.s ++ "+" ++ s2.s};
     appSentences s1 ss = {s = s1.s ++ "+" ++ ss.s};  
    
     And  = aggregateVP and_Conj; 
     Or    = aggregateVP or_Conj;  
       

 


    oper 
   
       adjToCN : C.A -> C.CN = 
                 \ap -> {s = \\n => (mkRS (mkRCl which_RP (mkVP ap))).s ! CR.Indic ! CR.agrP3 CR.Masc n; 
                              g = CR.Masc; lock_CN=<>} ;

       verbToCN : C.V ->C.CN = 
                 \v ->  { s = \\n =>  (mkRS (mkRCl which_RP (mkVP v))).s ! CR.Indic ! CR.agrP3 CR.Masc n;
                              g = CR.Masc;lock_CN=<>};
       
       nounToVP : C.N -> R.VP = \n -> mkVP n ;
 
       adjToVP : C.A -> R.VP = \a -> mkVP a ; 
       

       aggregateVP : C.Conj -> PropertyPart -> PropertyPart -> Property = 
             \conj, pp1, pp2 ->
                   case <pp1.sort,pp2.sort> of 
                     {<SNoun,SNoun> => cnToVP (nounsToComp conj pp1.noun pp2.noun); 
                      <SNoun,SAdj> => adjToVP (mixedToComp conj pp1.noun pp2.adj) ;
                      <SAdj,SNoun> => adjToVP (mixedToComp conj pp2.noun pp1.adj) ;
                      <SAdj,SAdj> => adjToVP (adjsToComp conj pp1.adj pp2.adj);
                      _                    => coordVP conj pp1.verb pp2.verb   
                     } ;                     
                     

   mixedToComp : C.Conj -> C.CN -> C.A -> C.A =
      \conj,cn1,a2 -> { s = \\d,c => 
                                           case c of 
                                                {CR.AF g n => (Coord.conjunctDistrSS conj (Coord.twoSS  ( ss (cn1.s ! n)) (ss (a2.s ! CR.Posit ! c)))).s ;
                                                 CR.AA => a2.s ! CR.Posit ! c}; 
                isPre = False; lock_A = <>};  
   
   mixedToCompSwapped : C.Conj -> C.A -> C.CN -> C.A = 
        \conj,a2,cn1 -> { s = \\d,c => 
                                           case c of 
                                                {CR.AF g n => (Coord.conjunctDistrSS conj (Coord.twoSS  ( ss (cn1.s ! n)) (ss (a2.s ! CR.Posit ! c)))).s ;
                                                 CR.AA => a2.s ! CR.Posit ! c}; 
                isPre = False; lock_A = <>};  

   nounsToComp : C.Conj -> C.CN -> C.CN -> C.CN =
     \conj,cn1,cn2 -> { s = \\n => (Coord.conjunctDistrSS conj (Coord.twoSS  ( ss (cn1.s ! n)) (ss (cn2.s ! n)))).s; g = cn2.g; lock_CN = <>};
                                     

  adjsToComp : C.Conj -> C.A -> C.A -> C.A = 
      \conj,a1,a2 -> { s = \\d,c => (Coord.conjunctDistrSS conj (Coord.twoSS  ( ss (a1.s ! d ! c)) (ss (a2.s ! d ! c)))).s ;
                isPre = False; lock_A = <>};  


   cnToVP : C.CN -> R.VP = \cn -> mkVP cn ;
 
   dummyAdj : C.A = {s=\\_,_ => ""; isPre = False; lock_A=<>};


  coordVP : C.Conj -> R.VP -> R.VP -> R.VP = 
       \conj, vp1, vp2 ->
            { s =  {s = \\vf => (Coord.conjunctDistrSS conj (Coord.twoSS  ( ss ((vp1.s).s ! vf)) (ss ((vp2.s).s ! vf)))).s; vtyp = (vp2.s).vtyp} ;
              agr = vp2.agr; neg = vp2.neg; clit1 = vp2.clit1; clit2 = vp2.clit2; clit3 = vp2.clit3;
              comp = \\a => vp1.comp ! a ++ vp2.comp ! a;
              ext = \\p => vp1.ext ! p ++ vp2.ext ! p
             };

--Italian : 

      all_Det : C.Det = {s,sp = \\g,c => R.prepCase c ++ CR.genForms "Tutti" "Tutte" ! g ; n = Pl ; s2 = []; lock_Det=<>} ;
      no_Det : C.Det = {s = \\g,c => R.prepCase c ++ CR.genForms "Nessun" "Nessuna" ! g ;
                                  sp = \\g,c => R.prepCase c ++ CR.genForms "Nessuno" "Nessuna" ! g ; 
                                  n = Sg ; s2 = []; lock_Det=<>} ;
      some_Det : C.Det = {s,sp = \\_,c => R.prepCase c ++ "Qualche" ; n = Pl ; s2 = []; lock_Det=<>} ;
      every_Det : C.Det = {s,sp = \\_,_ => "Ogni" ;  n = Sg ; s2 = [];lock_Det=<>} ;


}
